#include "timer.h"
#include "event.h"

timer::timer(int _id){
	flag = 0;
	id = _id;
}


timer::~timer(){
	if( flag == 1){
		stopTimer();
	}
}

void timer::timeout(){
	printf("timeout now\n");
	dll.handle_timeout(id);
}


void timer::startTimer(int time, int utime ){
	
	evtimer_set(&timeEvent, timeInput, this);
	struct timeval tv;
	tv.tv_sec	= time;
	tv.tv_usec	= utime;
	flag = 1;
	evtimer_add(&timeEvent, &tv);
}

void timer::stopTimer(){
	flag = 0;
	evtimer_del(&timeEvent);
}

map<int, timer*> g_TimerMap;




